var apiUrl = 'https://saler.jkcae.com/app'

var baseUrl = '';
if (process.env.NODE_ENV === 'development') {
	baseUrl = 'https://saler.jkcae.com/app'
} else {
	baseUrl = apiUrl
}
const request = (url = '', date = {}, type = 'post', header = {}) => {
	var token = uni.getStorageSync('h5-token') || '';
	var isAgent = uni.getStorageSync('h5-isAgent') || ''
	return new Promise((resolve, reject) => {
		uni.request({
			method: type,
			url: baseUrl + url,
			data: date,
			header: {
				"Authorization": token,
				"Platform": isAgent == 0 ? 3 : 1
			},
		}).then((res) => {
			resolve(res.data);
			if (res.data.code == 401) {
				uni.removeStorageSync('h5-token');
				uni.removeStorageSync('userInfo');
				uni.removeStorageSync('h5-isAgent');
				setTimeout(() => {
					uni.redirectTo({
						url: '/pages/login/login'
						// url: '/pages/distributorsRegister/distributorsRegister'
					})
				}, 1500)
			}
		}).catch(error => {
			reject(error);
		})
	})
}

export default request